home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / games / IndiZone / oort / configure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  22.2 KB  |  1,027 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*------------------------------------------------------------------------------
  18.  *
  19.  * OORT - configure.c - Routines for configuring vehicle.
  20.  *
  21.  * $Id: configure.c,v 1.3 1994/01/28 00:16:53 mtj Exp $
  22.  * 
  23.  * Chris Fouts - May, 1993.
  24.  * 
  25.  *----------------------------------------------------------------------------*/
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <unistd.h>
  30. #include <math.h>
  31. #include <string.h>
  32. #include <gl.h>
  33. #include <Performer/pf.h>
  34.  
  35. #include "oort.h"
  36. #include "input.h"
  37. #include "sound.h"
  38. #include "configure.h"
  39. #include "dashboard.h"
  40. #include "text.h"
  41.  
  42. #define    N_BUTTONS        23
  43. #define    N_OPTION_BUTTONS    18
  44.  
  45. #define    LABEL_TITLE    0
  46. #define    LABEL_SHIELD    1
  47. #define    LABEL_LASER    2
  48. #define    LABEL_ENGINE    3
  49. #define    LABEL_ECM    4
  50. #define    LABEL_SOLAR    5
  51. #define    LABEL_TRANSM    6
  52. #define    N_LABELS    7
  53.  
  54. #define    SHIELD_BUTTON    0
  55. #define    LASER_BUTTON    3
  56. #define    ENGINE_BUTTON    6
  57. #define    ECM_BUTTON    9
  58. #define    SOLAR_BUTTON    12
  59. #define    TRANSM_BUTTON    15
  60. #define    TEAM_A_BUTTON    18
  61. #define    TEAM_B_BUTTON    19
  62. #define    TEAM_C_BUTTON    20
  63. #define    TEAM_D_BUTTON    21
  64. #define    OK_BUTTON    22
  65.  
  66. #define    MAX_ACCEL    5.0f
  67. #define    SHIELD_FACTOR    1.0f
  68. #define    LASER_FACTOR    1.0f
  69. #define    ENGINE_FACTOR    0.125f
  70. #define    ECM_FACTOR    1.0f
  71. #define    SOLAR_FACTOR    1.0f
  72.  
  73. static float    enginePower[3] = { 0.8f, 1.0f, 1.2f } ;
  74. static float    gearing[3] = { 0.8f, 1.0f, 1.2f } ;
  75. static float    shieldCoeff[3] = { 1.0f, 1.2f, 1.4f } ;
  76. static float    laserCoeff[3] = { 0.6f, 0.8f, 1.0f } ;
  77. static float    engineCoeff[3] = { 1.0f, 1.2f, 1.4f } ;
  78. static float    ecmTime[3] = { 10.0f, 30.0f, 60.0f } ;
  79. static float    solarCoeff[3] = { 1.0f, 1.5f, 2.0f } ;
  80.  
  81. static int    shieldValue    = 0 ;
  82. static int    laserValue    = 0 ;
  83. static int    engineValue    = 0 ;
  84. static int    ecmValue    = 0 ;
  85. static int    solarValue    = 0 ;
  86. static int    transmValue    = 1 ;
  87. static int    doneValue    = 0 ;
  88. static int    teamValue    = 0 ;
  89.  
  90. float    topSpeed = 1.0f ;
  91. float    accelFactor ;
  92. float    shieldFactor ;
  93. float    laserFactor ;
  94. float    engineRate ;
  95. float    cloakRate ;
  96. float    solarRate ;
  97.  
  98.  
  99.  
  100. extern ViewPort    mainVP ;
  101. extern GeoFont    *helvFont ;
  102. extern int    leftMouseHit ;
  103. extern float    mouseX ;
  104. extern float    mouseY ;
  105. extern int    selfStatus ;
  106. extern pfVec3    teamColor[] ;
  107. extern Player    player[] ;
  108. extern int    numberPlayers ;
  109.  
  110. static struct Button {
  111.     float    l ;
  112.     float    r ;
  113.     float    b ;
  114.     float    t ;
  115.     float    x ;
  116.     float    y ;
  117.     int    *property ;
  118.     int    value ;
  119.     long    hiColor ;
  120.     long    medColor ;
  121.     long    loColor ;
  122.     long    textColor ;
  123.     int    status ;
  124.     GeoFont    *gf ;
  125.     char    *text ;
  126.     } button[N_BUTTONS] ;
  127.  
  128. static struct Label {
  129.     float    x ;
  130.     float    y ;
  131.     char    *text ;
  132.     GeoFont    *gf ;
  133.     } label[N_LABELS] ;
  134.  
  135. static char    *numberLabel[] = { "0", "1", "2" } ;
  136. static char    *gearedLabel[] = { "L", "M", "H" } ;
  137. static char    *teamLabel[] = { "A", "B", "C", "D" } ;
  138. static char    *labelText[] = {
  139.             "Vehicle Configuration",
  140.             "Shields",
  141.             "Laser",
  142.             "Engine",
  143.             "ECM",
  144.             "Solar Panels",
  145.             "Gearing",
  146.             } ;
  147.  
  148. static long    hbc = 0x00a0b010 ;
  149. static long    mbc = 0x00707010 ;
  150. static long    lbc = 0x00304000 ;
  151. static long    ahbc = 0x0010b0a0 ;
  152. static long    ambc = 0x00107070 ;
  153. static long    albc = 0x00004030 ;
  154.  
  155. static float    configStatusY ;
  156.  
  157. /* BEGIN PROTOTYPES -S configure.c */
  158. static long     darkerColor( long c ) ;
  159. static void     drawButton( struct Button *b ) ;
  160. static void     HSVtoRGB( pfVec3 hsv, pfVec3 rgb ) ;
  161. static long     lighterColor( long c ) ;
  162. static long     packedColor( pfVec3 v ) ;
  163. static void     pressButton( void ) ;
  164. static void     readyToLand( void ) ;
  165. static void     RGBtoHSV( pfVec3 rgb, pfVec3 hsv ) ;
  166. static void     setConfigFactors( void ) ;
  167. static void     setTeamButtonColor( int nButton, int nTeam ) ;
  168. static void     unpackedColor( long c, pfVec3 rgb ) ;
  169. /* END PROTOTYPES -S configure.c */
  170.  
  171.  
  172.  
  173. /*------------------------------------------------------------------------------
  174.  * Draw configuration screen.
  175.  *----------------------------------------------------------------------------*/
  176. void
  177. drawConfigureScreen(
  178.     pfChannel    *channel,
  179.     void        *data
  180.     )
  181. {
  182.     int    i ;
  183.     float    x ;
  184.     float    y ;
  185.     int    configPts ;
  186.     char    str[256] ;
  187.     int    teamCount[4] ;
  188.  
  189.     pfPushState();
  190.     pfBasicState();
  191.  
  192.     /*
  193.      * Get input.
  194.      */
  195.     grabInput() ;
  196.  
  197.     /*
  198.      * Check for button presses.
  199.      */
  200.     if( leftMouseHit )
  201.     {
  202.         leftMouseHit = 0 ;
  203.         pressButton() ;
  204.     }
  205.     else
  206.     {
  207.     }
  208.  
  209.     if( mainVP.right - mainVP.left > mainVP.top - mainVP.bottom )
  210.     {
  211.         y = mainVP.top - mainVP.bottom ;
  212.         x = (float)( mainVP.right - mainVP.left ) / y ;
  213.         y = 1.0f ;
  214.     }
  215.     else
  216.     {
  217.         x = mainVP.right - mainVP.left ;
  218.         y = (float)( mainVP.top - mainVP.bottom ) / x;
  219.         x = 1.0f ;
  220.     }
  221.  
  222.     pfPushIdentMatrix() ;
  223.     ortho2( -x, x, -y, y ) ;
  224.  
  225.     zfunction( ZF_ALWAYS ) ;
  226.     zwritemask( 0x0 ) ;
  227.     shademodel( GOURAUD ) ;
  228.     cpack( 0x0 ) ;
  229.     clear() ;
  230.  
  231.     cpack( 0x0000ffff ) ;
  232.     for( i = 0 ; i < N_LABELS ; i++ )
  233.     {
  234.         positionText( label[i].x, label[i].y ) ;
  235.         drawString( label[i].gf, label[i].text ) ;
  236.     }
  237.  
  238.     for( i = 0 ; i < N_BUTTONS ; i++ )
  239.     {
  240.         drawButton( &(button[i]) ) ;
  241.     }
  242.  
  243.     configPts = shieldValue + laserValue + engineValue + ecmValue +
  244.             solarValue ;
  245.     if( configPts > 4 )
  246.     {
  247.         cpack( 0x000000ff ) ;
  248.         sprintf( str, "Maximum configuration points (4) exceeded." ) ;
  249.     }
  250.     else
  251.     {
  252.         cpack( 0x0000ff00 ) ;
  253.         sprintf( str, "Configuration points available: %d",
  254.             4 - configPts ) ;
  255.     }
  256.     positionText( -0.5f * getStrWidth( label[1].gf, str ), configStatusY ) ;
  257.     drawString( label[1].gf, str ) ;
  258.  
  259.     teamCount[0] = 0 ;
  260.     teamCount[1] = 0 ;
  261.     teamCount[2] = 0 ;
  262.     teamCount[3] = 0 ;
  263.     for( i = 0 ; i < numberPlayers ; i++ )
  264.     {
  265.         teamCount[player[i].team] += 1 ;
  266.     }
  267.     c3f( teamColor[teamValue] ) ;
  268.     sprintf( str, "Team (A:%d B:%d C:%d D:%d)", teamCount[0], teamCount[1],
  269.         teamCount[2], teamCount[3] ) ;
  270.     positionText( label[1].x, button[TEAM_A_BUTTON].b ) ;
  271.     drawString( label[1].gf, str ) ;
  272.  
  273.     pfPopMatrix() ;
  274.  
  275.     if( doneValue && button[OK_BUTTON].status == 0 )
  276.     {
  277.         if( configPts <= 4 )
  278.         {
  279.             readyToLand() ;
  280.         }
  281.         else
  282.         {
  283.             postNewMessage( "Too many configuration points used." );
  284.         }
  285.         doneValue = 0 ;
  286.         button[OK_BUTTON].loColor = lbc ;
  287.         button[OK_BUTTON].medColor = mbc ;
  288.         button[OK_BUTTON].hiColor = hbc ;
  289.     }
  290.  
  291.     zfunction( ZF_LEQUAL ) ;
  292.     zwritemask( 0xffffffff ) ;
  293.     pfPopState();
  294. }
  295.  
  296.  
  297.  
  298. /*------------------------------------------------------------------------------
  299.  * Draw a 3D button.
  300.  *----------------------------------------------------------------------------*/
  301. static void
  302. drawButton(
  303.     struct Button    *b
  304.     )
  305. {
  306.     long    c ;
  307.     float    v[2] ;
  308.     float    d ;
  309.     float    e ;
  310.  
  311.     d = 0.15 * ( b->t - b->b ) ;
  312.     e = 1.5f * d ;
  313.  
  314.     cpack( b->medColor ) ;
  315.     bgntmesh() ;
  316.         v[0] = b->l + d ; v[1] = b->b + d ; v2f( v ) ;
  317.         v[0] = b->r - d ;                   v2f( v ) ;
  318.         v[0] = b->l + d ; v[1] = b->t - d ; v2f( v ) ;
  319.         v[0] = b->r - d ;                   v2f( v ) ;
  320.     endtmesh() ;
  321.  
  322.     bgntmesh() ;
  323.         cpack( b->loColor ) ;
  324.         v[0] = b->l + e ; v[1] = b->b + d ; v2f( v ) ;
  325.         v[0] = b->l + d ; v[1] = b->b     ; v2f( v ) ;
  326.         v[0] = b->r - e ; v[1] = b->b + d ; v2f( v ) ;
  327.         v[0] = b->r - d ; v[1] = b->b     ; v2f( v ) ;
  328.  
  329.         v[0] = b->r - d ; v[1] = b->b + e ; v2f( v ) ;
  330.         v[0] = b->r     ; v[1] = b->b + d ; v2f( v ) ;
  331.         v[0] = b->r - d ; v[1] = b->t - e ; v2f( v ) ;
  332.         v[0] = b->r     ; v[1] = b->t - d ; v2f( v ) ;
  333.  
  334.         cpack( b->hiColor ) ;
  335.         v[0] = b->r - e ; v[1] = b->t - d ; v2f( v ) ;
  336.         v[0] = b->r - d ; v[1] = b->t     ; v2f( v ) ;
  337.         v[0] = b->l + e ; v[1] = b->t - d ; v2f( v ) ;
  338.         v[0] = b->l + d ; v[1] = b->t     ; v2f( v ) ;
  339.  
  340.         v[0] = b->l + d ; v[1] = b->t - e ; v2f( v ) ;
  341.         v[0] = b->l     ; v[1] = b->t - d ; v2f( v ) ;
  342.         v[0] = b->l + d ; v[1] = b->b + e ; v2f( v ) ;
  343.         v[0] = b->l     ; v[1] = b->b + d ; v2f( v ) ;
  344.  
  345.         cpack( b->loColor ) ;
  346.         v[0] = b->l + e ; v[1] = b->b + d ; v2f( v ) ;
  347.         v[0] = b->l + d ; v[1] = b->b     ; v2f( v ) ;
  348.     endtmesh() ;
  349.  
  350.     cpack( b->textColor ) ;
  351.     positionText( b->x, b->y ) ;
  352.     drawString( b->gf, b->text ) ;
  353.  
  354.     if( b->status == 1 )
  355.     {
  356.         c = b->loColor ;
  357.         b->loColor = b->hiColor ;
  358.         b->hiColor = c ;
  359.         b->status = 0 ;
  360.     }
  361. }
  362.  
  363.  
  364.  
  365. /*------------------------------------------------------------------------------
  366.  * Initialize the configuration screen structures.
  367.  *----------------------------------------------------------------------------*/
  368. void
  369. initConfigureScreen(
  370.     void
  371.     )
  372. {
  373.     int    i ;
  374.     float    x ;
  375.     float    y ;
  376.     float    xStart ;
  377.     float    w ;
  378.     float    gap ;
  379.     GeoFont    *bf ;
  380.     GeoFont    *tf ;
  381.     GeoFont    *lf ;
  382.  
  383.     w = 0.13 ;
  384.     gap = 0.05 ;
  385.     xStart = -0.75f ;
  386.  
  387.     bf = copyFont( helvFont ) ;
  388.     setFontSize( bf, 0.5f * w ) ;
  389.  
  390.     tf = copyFont( helvFont ) ;
  391.     setFontSize( tf, 0.20f ) ;
  392.  
  393.     lf = copyFont( helvFont ) ;
  394.     setFontSize( lf, w ) ;
  395.  
  396.     button[SHIELD_BUTTON+0].property = &shieldValue ;
  397.     button[SHIELD_BUTTON+1].property = &shieldValue ;
  398.     button[SHIELD_BUTTON+2].property = &shieldValue ;
  399.  
  400.     button[LASER_BUTTON+0].property = &laserValue ;
  401.     button[LASER_BUTTON+1].property = &laserValue ;
  402.     button[LASER_BUTTON+2].property = &laserValue ;
  403.  
  404.     button[ENGINE_BUTTON+0].property = &engineValue ;
  405.     button[ENGINE_BUTTON+1].property = &engineValue ;
  406.     button[ENGINE_BUTTON+2].property = &engineValue ;
  407.  
  408.     button[ECM_BUTTON+0].property = &ecmValue ;
  409.     button[ECM_BUTTON+1].property = &ecmValue ;
  410.     button[ECM_BUTTON+2].property = &ecmValue ;
  411.  
  412.     button[SOLAR_BUTTON+0].property = &solarValue ;
  413.     button[SOLAR_BUTTON+1].property = &solarValue ;
  414.     button[SOLAR_BUTTON+2].property = &solarValue ;
  415.  
  416.     button[TRANSM_BUTTON+0].property = &transmValue ;
  417.     button[TRANSM_BUTTON+1].property = &transmValue ;
  418.     button[TRANSM_BUTTON+2].property = &transmValue ;
  419.  
  420.     /*
  421.      * Initialize button locations.
  422.      */
  423.     y = 0.75f ;
  424.     for( i = 0 ; i < TRANSM_BUTTON ; i++ )
  425.     {
  426.         if( i % 3 == 0 )
  427.         {
  428.             x = xStart ;
  429.             y = y - w - gap ;
  430.         }
  431.         else
  432.         {
  433.             x += w + gap ;
  434.         }
  435.         if( i % 3 == *(button[i].property) )
  436.         {
  437.             button[i].hiColor = ahbc ;
  438.             button[i].medColor = ambc ;
  439.             button[i].loColor = albc ;
  440.         }
  441.         else
  442.         {
  443.             button[i].hiColor = hbc ;
  444.             button[i].medColor = mbc ;
  445.             button[i].loColor = lbc ;
  446.         }
  447.         button[i].l = x ;
  448.         button[i].r = x + w ;
  449.         button[i].b = y ;
  450.         button[i].t = y + w ;
  451.  
  452.         button[i].text = numberLabel[i%3] ;
  453.         button[i].x = x + 0.5f *
  454.                 ( w - getStrWidth( bf, button[i].text ) ) ;
  455.         button[i].y = y + 0.25f * w ;
  456.  
  457.         button[i].gf = bf ;
  458.         button[i].value = i % 3 ;
  459.         button[i].textColor = 0x00ffffff ;
  460.         button[i].status = 0 ;
  461.     }
  462.  
  463.     y -= 1.2f * w ;
  464.     configStatusY = y ;
  465.  
  466.     x = xStart ;
  467.     y -= 1.5f * w ;
  468.     for( i = TRANSM_BUTTON ; i < TRANSM_BUTTON + 3 ; i++ )
  469.     {
  470.         if( i % 3 == *(button[i].property) )
  471.         {
  472.             button[i].hiColor = ahbc ;
  473.             button[i].medColor = ambc ;
  474.             button[i].loColor = albc ;
  475.         }
  476.         else
  477.         {
  478.             button[i].hiColor = hbc ;
  479.             button[i].medColor = mbc ;
  480.             button[i].loColor = lbc ;
  481.         }
  482.         button[i].l = x ;
  483.         button[i].r = x + w ;
  484.         button[i].b = y ;
  485.         button[i].t = y + w ;
  486.  
  487.         button[i].text = gearedLabel[i%3] ;
  488.         button[i].x = x + 0.5f *
  489.                 ( w - getStrWidth( bf, button[i].text ) ) ;
  490.         button[i].y = y + 0.25f * w ;
  491.  
  492.         button[i].gf = bf ;
  493.         button[i].value = i % 3 ;
  494.         button[i].textColor = 0x00ffffff ;
  495.         button[i].status = 0 ;
  496.  
  497.         x += w + gap ;
  498.     }
  499.  
  500.     button[TEAM_A_BUTTON].property = &teamValue ;
  501.     button[TEAM_B_BUTTON].property = &teamValue ;
  502.     button[TEAM_C_BUTTON].property = &teamValue ;
  503.     button[TEAM_D_BUTTON].property = &teamValue ;
  504.  
  505.     x = xStart ;
  506.     y -= 1.5f * w ;
  507.     for( i = TEAM_A_BUTTON ; i <= TEAM_D_BUTTON ; i++ )
  508.     {
  509.         setTeamButtonColor( i, i-TEAM_A_BUTTON ) ;
  510.  
  511.         button[i].l = x ;
  512.         button[i].r = x + w ;
  513.         button[i].b = y ;
  514.         button[i].t = y + w ;
  515.  
  516.         button[i].text = teamLabel[i-TEAM_A_BUTTON] ;
  517.         button[i].x = x + 0.5f *
  518.                 ( w - getStrWidth( bf, button[i].text ) ) ;
  519.         button[i].y = y + 0.25f * w ;
  520.  
  521.         button[i].gf = bf ;
  522.         button[i].value = i - TEAM_A_BUTTON ;
  523.         button[i].textColor = 0x0 ;
  524.         button[i].status = 0 ;
  525.  
  526.         x += w + gap ;
  527.     }
  528.  
  529.     x = -w ;
  530.     y -= 1.5f * w ;
  531.     i = OK_BUTTON ;
  532.     button[i].hiColor = hbc ;
  533.     button[i].medColor = mbc ;
  534.     button[i].loColor = lbc ;
  535.     button[i].l = x ;
  536.     button[i].r = x + 2.0f * w ;
  537.     button[i].b = y ;
  538.     button[i].t = y + w ;
  539.  
  540.     button[i].text = strdup( "Done" ) ;
  541.     button[i].x = x + 0.5f *
  542.             ( 2.0f * w - getStrWidth( bf, button[i].text ) ) ;
  543.     button[i].y = y + 0.25f * w ;
  544.  
  545.     button[i].gf = bf ;
  546.     button[i].value = 1 ;
  547.     button[i].textColor = 0x00ffffff ;
  548.     button[i].status = 0 ;
  549.     button[i].property = &doneValue ;
  550.  
  551.     /*
  552.      * Initialize labels.
  553.      */
  554.     y = 0.80f ;
  555.     label[LABEL_TITLE].text = labelText[LABEL_TITLE] ;
  556.     label[LABEL_TITLE].gf = tf ;
  557.     label[LABEL_TITLE].x = -0.5f * getStrWidth( tf,
  558.                         labelText[LABEL_TITLE] ) ;
  559.     label[LABEL_TITLE].y = y ;
  560.  
  561.     x = xStart + 4.0f * ( w + gap ) ;
  562.  
  563.     label[LABEL_SHIELD].text = labelText[LABEL_SHIELD] ;
  564.     label[LABEL_SHIELD].gf = lf ;
  565.     label[LABEL_SHIELD].x = x ;
  566.     label[LABEL_SHIELD].y = button[SHIELD_BUTTON].b ;
  567.  
  568.     label[LABEL_LASER].text = labelText[LABEL_LASER] ;
  569.     label[LABEL_LASER].gf = lf ;
  570.     label[LABEL_LASER].x = x ;
  571.     label[LABEL_LASER].y = button[LASER_BUTTON].b ;
  572.  
  573.     label[LABEL_ENGINE].text = labelText[LABEL_ENGINE] ;
  574.     label[LABEL_ENGINE].gf = lf ;
  575.     label[LABEL_ENGINE].x = x ;
  576.     label[LABEL_ENGINE].y = button[ENGINE_BUTTON].b ;
  577.  
  578.     label[LABEL_ECM].text = labelText[LABEL_ECM] ;
  579.     label[LABEL_ECM].gf = lf ;
  580.     label[LABEL_ECM].x = x ;
  581.     label[LABEL_ECM].y = button[ECM_BUTTON].b ;
  582.  
  583.     label[LABEL_SOLAR].text = labelText[LABEL_SOLAR] ;
  584.     label[LABEL_SOLAR].gf = lf ;
  585.     label[LABEL_SOLAR].x = x ;
  586.     label[LABEL_SOLAR].y = button[SOLAR_BUTTON].b ;
  587.  
  588.     label[LABEL_TRANSM].text = labelText[LABEL_TRANSM] ;
  589.     label[LABEL_TRANSM].gf = lf ;
  590.     label[LABEL_TRANSM].x = x ;
  591.     label[LABEL_TRANSM].y = button[TRANSM_BUTTON].b ;
  592.  
  593.     setConfigFactors() ;
  594. }
  595.  
  596.  
  597.  
  598. /*------------------------------------------------------------------------------
  599.  * Check for clicking on buttons.
  600.  *----------------------------------------------------------------------------*/
  601. static void
  602. pressButton(
  603.     void
  604.     )
  605. {
  606.     int    i ;
  607.     int    j ;
  608.     int    k ;
  609.     long    c ;
  610.     float    x ;
  611.     float    y ;
  612.  
  613.     for( i = 0 ; i < N_OPTION_BUTTONS ; i++ )
  614.     {
  615.         if( button[i].l <= mouseX && mouseX <= button[i].r &&
  616.             button[i].b <= mouseY && mouseY <= button[i].t )
  617.         {
  618.             *(button[i].property) = button[i].value ;
  619.             k = i - ( i % 3 ) ;
  620.             for( j = 0 ; j < 3 ; j++ )
  621.             {
  622.                 if( ( i % 3 ) == j )
  623.                 {
  624.                     button[k+j].status = 1 ;
  625.                     button[k+j].loColor = ahbc ;
  626.                     button[k+j].medColor = ambc ;
  627.                     button[k+j].hiColor = albc ;
  628.                 }
  629.                 else
  630.                 {
  631.                     button[k+j].loColor = lbc ;
  632.                     button[k+j].medColor = mbc ;
  633.                     button[k+j].hiColor = hbc ;
  634.                 }
  635.             }
  636.             if( shieldValue + laserValue + engineValue +
  637.                 ecmValue + solarValue > 4 )
  638.             {
  639.                 sfx( SFX_NOT_OK ) ;
  640.             }
  641.             else
  642.             {
  643.                 sfx( SFX_OK ) ;
  644.             }
  645.         }
  646.     }
  647.  
  648.     for( i = N_OPTION_BUTTONS ; i < TEAM_D_BUTTON + 1 ; i++ )
  649.     {
  650.         if( button[i].l <= mouseX && mouseX <= button[i].r &&
  651.             button[i].b <= mouseY && mouseY <= button[i].t )
  652.         {
  653.             *(button[i].property) = button[i].value ;
  654.             c = button[i].loColor ;
  655.             button[i].loColor = button[i].hiColor ;
  656.             button[i].hiColor = c ;
  657.             button[i].status = 1 ;
  658.             player[SELF].team = i - TEAM_A_BUTTON ;
  659.             sfx( SFX_OK ) ;
  660.         }
  661.     }
  662.  
  663.     for( i = TEAM_D_BUTTON + 1 ; i < N_BUTTONS ; i++ )
  664.     {
  665.         if( button[i].l <= mouseX && mouseX <= button[i].r &&
  666.             button[i].b <= mouseY && mouseY <= button[i].t )
  667.         {
  668.             *(button[i].property) = button[i].value ;
  669.             button[i].loColor = hbc ;
  670.             button[i].medColor = mbc ;
  671.             button[i].hiColor = lbc ;
  672.             button[i].status = 1 ;
  673.             sfx( SFX_OK ) ;
  674.         }
  675.     }
  676. }
  677.  
  678.  
  679.  
  680. /*------------------------------------------------------------------------------
  681.  * Prepare to land.
  682.  *----------------------------------------------------------------------------*/
  683. static void
  684. readyToLand(
  685.     void
  686.     )
  687. {
  688.     selfStatus = OORT_ST_IN_ORBIT ;
  689.     leftMouseHit = 0 ;
  690.     setMainDrawFunction() ;
  691.  
  692.     setConfigFactors() ;
  693. }
  694.  
  695.  
  696.  
  697.  
  698. /*------------------------------------------------------------------------------
  699.  * Set the various configuration factors.
  700.  *----------------------------------------------------------------------------*/
  701. static void
  702. setConfigFactors(
  703.     void
  704.     )
  705. {
  706.     topSpeed = MAX_SPEED * enginePower[engineValue] * gearing[transmValue] ;
  707.     accelFactor = MAX_ACCEL * enginePower[engineValue] /
  708.             gearing[transmValue] / gearing[transmValue] ;
  709.     shieldFactor = SHIELD_FACTOR * shieldCoeff[shieldValue] ;
  710.     laserFactor = LASER_FACTOR * laserCoeff[laserValue] ;
  711.     engineRate = ENGINE_FACTOR * engineCoeff[engineValue] ;
  712.     cloakRate = ECM_FACTOR / ecmTime[ecmValue] ;
  713.     solarRate = SOLAR_FACTOR * solarCoeff[solarValue] ;
  714.     player[SELF].team = teamValue ;
  715. }
  716.  
  717.  
  718.  
  719. /*------------------------------------------------------------------------------
  720.  * Convert a vector color to a packed color.
  721.  *----------------------------------------------------------------------------*/
  722. static long
  723. packedColor(
  724.     pfVec3    v
  725.     )
  726. {
  727.     int    i ;
  728.     long    c = 0 ;
  729.  
  730.     for( i = 2 ; i >= 0 ; i-- )
  731.     {
  732.         c = c << 8 ;
  733.         c |= (unsigned int)( v[i] * 255.0f ) & 0x0ff ;
  734.     }
  735.  
  736.     return( c ) ;
  737. }
  738.  
  739.  
  740.  
  741. /*------------------------------------------------------------------------------
  742.  * Return a lighter color.
  743.  *----------------------------------------------------------------------------*/
  744. static long
  745. lighterColor(
  746.     long    c
  747.     )
  748. {
  749.     pfVec3    rgb ;
  750.     pfVec3    hsv ;
  751.  
  752.     unpackedColor( c, rgb ) ;
  753.     RGBtoHSV( rgb, hsv ) ;
  754.     hsv[2] += 0.2 ;
  755.     if( hsv[2] > 1.0 ) {
  756.         hsv[1] *= 0.75 ;
  757.         hsv[2] = 1.0 ;
  758.         }
  759.     HSVtoRGB( hsv, rgb ) ;
  760.     return( packedColor( rgb ) ) ;
  761. }
  762.  
  763.  
  764.  
  765. /*------------------------------------------------------------------------------
  766.  * Return a darker color.
  767.  *----------------------------------------------------------------------------*/
  768. static long
  769. darkerColor(
  770.     long    c
  771.     )
  772. {
  773.     pfVec3    rgb ;
  774.     pfVec3    hsv ;
  775.  
  776.     unpackedColor( c, rgb ) ;
  777.     RGBtoHSV( rgb, hsv ) ;
  778.     hsv[2] -= 0.2 ;
  779.     if( hsv[2] < 0.0 )
  780.         return( 0 ) ;
  781.     HSVtoRGB( hsv, rgb ) ;
  782.     return( packedColor( rgb ) ) ;
  783. }
  784.  
  785.  
  786.  
  787. /*------------------------------------------------------------------------------
  788.  * Unpack a color.
  789.  *----------------------------------------------------------------------------*/
  790. static void
  791. unpackedColor(
  792.     long    c,
  793.     pfVec3    rgb
  794.     )
  795. {
  796.     int    i ;
  797.  
  798.     for( i = 0 ; i < 3 ; i++ )
  799.     {
  800.         rgb[i] = (float)( c & 0x0ff ) / 255.0f ;
  801.         c = c >> 8 ;
  802.     }
  803. }
  804.  
  805.  
  806.  
  807. /*------------------------------------------------------------------------------
  808.  * Convert from HSV to RGB space.
  809.  *----------------------------------------------------------------------------*/
  810. static void
  811. HSVtoRGB(
  812.     pfVec3    hsv,
  813.     pfVec3    rgb
  814.     )
  815. {
  816.     int    i ;
  817.     float    f ;
  818.     float    p ;
  819.     float    q ;
  820.     float    t ;
  821.  
  822.     hsv[0] *= 360.0f ;
  823.     if( hsv[1] == 0.0f )
  824.     {
  825.         rgb[0] = hsv[2] ;
  826.         rgb[1] = hsv[2] ;
  827.         rgb[2] = hsv[2] ;
  828.     }
  829.     else
  830.     {
  831.         if( hsv[0] == 360.0f ) 
  832.             hsv[0] = 0.0f ;
  833.         hsv[0] /= 60.0f ;
  834.         i = floorf( hsv[0] ) ;
  835.         f = hsv[0] - i ;
  836.         p = hsv[2] * ( 1.0f - hsv[1] ) ;
  837.         q = hsv[2] * ( 1.0f - ( hsv[1] * f ) ) ;
  838.         t = hsv[2] * ( 1.0f - ( hsv[1] * ( 1.0f - f ) ) ) ;
  839.         switch( i )
  840.         {
  841.             case 0 : 
  842.                 rgb[0] = hsv[2] ;
  843.                 rgb[1] = t ;
  844.                 rgb[2] = p ;
  845.                 break ;
  846.             case 1 : 
  847.                 rgb[0] = q ;
  848.                 rgb[1] = hsv[2] ;
  849.                 rgb[2] = p ;
  850.                 break ;
  851.             case 2 : 
  852.                 rgb[0] = p ;
  853.                 rgb[1] = hsv[2] ;
  854.                 rgb[2] = t ;
  855.                 break ;
  856.             case 3 : 
  857.                 rgb[0] = p ;
  858.                 rgb[1] = q ;
  859.                 rgb[2] = hsv[2] ;
  860.                 break;
  861.             case 4 : 
  862.                 rgb[0] = t ;
  863.                 rgb[1] = p ;
  864.                 rgb[2] = hsv[2] ;
  865.                 break;
  866.             case 5 : 
  867.                 rgb[0] = hsv[2] ;
  868.                 rgb[1] = p ;
  869.                 rgb[2] = q ;
  870.                 break;
  871.         }
  872.     }
  873. }
  874.  
  875.  
  876.  
  877. /*------------------------------------------------------------------------------
  878.  * Convert from RGB space to HSV space.
  879.  *----------------------------------------------------------------------------*/
  880. static void
  881. RGBtoHSV(
  882.     pfVec3    rgb,
  883.     pfVec3    hsv
  884.     )
  885. {
  886.     float    h ;
  887.     float    s ;
  888.     float    v ;
  889.     float    cmax ;
  890.     float    cmin ;
  891.     float    cdelta ;
  892.     float    rc ;
  893.     float    gc ;
  894.     float    bc ;
  895.  
  896.     /* find the cmax and cmin of r g b */
  897.     cmax = rgb[0] ; 
  898.     cmin = rgb[0] ;
  899.     cmax = ( rgb[1] > cmax ? rgb[1] : cmax ) ;
  900.     cmin = ( rgb[1] < cmin ? rgb[1] : cmin ) ;
  901.     cmax = ( rgb[2] > cmax ? rgb[2] : cmax ) ;
  902.     cmin = ( rgb[2] < cmin ? rgb[2] : cmin ) ;
  903.     v = cmax ;
  904.     if( cmax != 0.0f )
  905.     {
  906.         s = ( cmax - cmin ) / cmax ;
  907.     }
  908.     else
  909.     {
  910.         s = 0.0f ;
  911.         h = 0.0f ;
  912.     }
  913.     if( s == 0.0f )
  914.     {
  915.         h = -1.0f ;
  916.     }
  917.     else
  918.     {
  919.         cdelta = cmax - cmin ;
  920.         rc = ( cmax - rgb[0] ) / cdelta ;
  921.         gc = ( cmax - rgb[1] ) / cdelta ;
  922.         bc = ( cmax - rgb[2] ) / cdelta ;
  923.         if( rgb[0] == cmax )
  924.         {
  925.             h = bc - gc ;
  926.         }
  927.         else if( rgb[1] == cmax )
  928.         {
  929.             h = 2.0f + rc - bc ;
  930.         }
  931.         else
  932.         {
  933.             h = 4.0f + gc - rc ;
  934.         }
  935.         h = h * 60.0f ;
  936.         if( h < 0.0f )
  937.             h += 360.0f ;
  938.     }
  939.     hsv[0] = h / 360.0f ;
  940.     hsv[1] = s ;
  941.     hsv[2] = v ;
  942. }
  943.  
  944.  
  945.  
  946. /*------------------------------------------------------------------------------
  947.  * Set a team selection button to the correct color.
  948.  *----------------------------------------------------------------------------*/
  949. static void
  950. setTeamButtonColor(
  951.     int    nButton,
  952.     int    nTeam
  953.     )
  954. {
  955.     long    c ;
  956.  
  957.     c = packedColor( teamColor[nTeam] ) ;
  958.     button[nButton].hiColor = lighterColor( c ) ;
  959.     button[nButton].medColor = c ;
  960.     button[nButton].loColor = darkerColor( c ) ;
  961. }
  962.  
  963.  
  964.  
  965. /*------------------------------------------------------------------------------
  966.  * Print out a message of the current configuration.
  967.  *----------------------------------------------------------------------------*/
  968. void
  969. showConfiguration(
  970.     void
  971.     )
  972. {
  973.     postNewMessage( "Shields:%d Laser:%d Engine:%d ECM:%d Solar:%d "
  974.             "Gearing:%c Team:%c", shieldValue, laserValue,
  975.             engineValue, ecmValue, solarValue, "LMH"[transmValue],
  976.             "ABCD"[teamValue] ) ;
  977. }
  978.  
  979.  
  980.  
  981. /*------------------------------------------------------------------------------
  982.  * Set the default configuration values.
  983.  *----------------------------------------------------------------------------*/
  984. int
  985. setDefaultConfig(
  986.     char    *str
  987.     )
  988. {
  989.     int    err ;
  990.     char    gear ;
  991.     char    team ;
  992.  
  993.     if( sscanf( str, "%d %d %d %d %d %c %c", &shieldValue, &laserValue,
  994.         &engineValue, &ecmValue, &solarValue, &gear, &team ) != 7 )
  995.     {
  996.         err = 1 ;
  997.     }
  998.     else if( shieldValue < 0 || shieldValue > 2 ||
  999.         laserValue < 0 || laserValue > 2 ||
  1000.         engineValue < 0 || engineValue > 2 ||
  1001.         ecmValue < 0 || ecmValue > 2 ||
  1002.         solarValue < 0 || solarValue > 2 ||
  1003.         ( gear != 'L' && gear != 'M' && gear != 'H' ) ||
  1004.         ( team != 'A' && team != 'B' && team != 'C' && team != 'D' ) )
  1005.     {
  1006.         err = 1 ;
  1007.     }
  1008.     else
  1009.     {
  1010.         transmValue = ( gear == 'L' ) ? 0 : ( ( gear == 'M' ) ? 1 : 2 );
  1011.         teamValue = team - 'A' ;
  1012.         err = 0 ;
  1013.     }
  1014.  
  1015.     if( err == 1 )
  1016.     {
  1017.         shieldValue = 0 ;
  1018.         laserValue = 0 ;
  1019.         engineValue = 0 ;
  1020.         ecmValue = 0 ;
  1021.         solarValue = 0 ;
  1022.     }
  1023.  
  1024.     return( err ) ;
  1025. }
  1026.  
  1027.